package ru.passivemoney.indicator.ac.optimization;

import java.io.File;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ru.passivemoney.common.Credentials;
import ru.passivemoney.root.Listener;

import com.dukascopy.api.system.IClient;
import com.dukascopy.api.system.ITesterClient;

public class ACOptimizationListener extends Listener {
	
	private static final Logger logger = LoggerFactory.getLogger(ACOptimizationListener.class);

	public ACOptimizationListener() {
	}

	public ACOptimizationListener(IClient client, Credentials credentials) {
		super(client, credentials);
	}

	@Override
	public void onStop(long processId) {
		logger.info("Strategy stopped: " + processId);
		
		File reportFile = new File("C:\\report_" + processId + ".html");
		try {
			((ITesterClient) getClient()).createReport(processId, reportFile);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
		}
		if (getClient().getStartedStrategies().size() == 0) {
			System.exit(0);
		}
	}

}